import http from '../../utils/http'
export const SAVE_CHANNELS = 'channel/SAVE_CHANNELS'
export const CHANGE_ACTIVE = 'channel/CHANGE_ACTIVE'

// 获取频道的异步 action
export const getChannels = () => {
  return async (dispatch) => {
    // 请求接口调用直接写异步 action 内部即可
    const res = await http.get(`/v1_0/channels`)
    console.log(`/v1_0/channels`, res)
    // 给 reducer 更新的 action
    dispatch({ type: SAVE_CHANNELS, payload: res.data.channels })
  }
}

// 同步 action (普通action)
export const changeActive = (id) => {
  // action 就是一个有 type 类型的普通对象
  return { type: CHANGE_ACTIVE, payload: id }
}
